package com.situ.mall.controller.back;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.situ.mall.common.ServerResponse;
import com.situ.mall.entity.Category;
import com.situ.mall.entity.Product;
import com.situ.mall.service.ICategoryService;
import com.situ.mall.service.IProductService;

@RequestMapping("/category")
@Controller
public class CategoryController {
	@Autowired
	private ICategoryService categoryService;
	//跳转到商品展示界面
	@RequestMapping("/getCategoryPage")
	public String getProductPage() {
		return "/category/category_list";
	}

	@RequestMapping("/list")
	@ResponseBody
	public List<Category> list() {
		return categoryService.list();
	}

	@RequestMapping("/pageList")
	@ResponseBody
	public ServerResponse pageList(Integer page, Integer limit) {
		ServerResponse serverResponse = categoryService.pageList(page, limit);
		System.out.println(serverResponse);
		return serverResponse;
	}

	@RequestMapping("/deleteById")
	@ResponseBody
	public ServerResponse deleteById(Integer id) {
		return categoryService.deleteById(id);
	}

	@RequestMapping("/deleteAll")
	@ResponseBody
	public ServerResponse deleteAll(String ids) {
		return categoryService.deleteAll(ids);
	}
	
	//跳转到商品添加界面
	@RequestMapping("/getAddPage")
	public String getAddPage() {
		return "/category/category_add";
	}
	//添加功能
	@RequestMapping("/add")
	@ResponseBody
	public ServerResponse add(Category category) {
		return categoryService.add(category);
	}
	// 一级联动
	@RequestMapping("/selectTopCategory")
	@ResponseBody
	public ServerResponse selectTopCategory() {
		
		return categoryService.selectTopCategory();
	}
	
	//二级联动
	@RequestMapping("/selectSecondCategory")
	@ResponseBody
	public ServerResponse selectScondCategory(Integer topCategoryId) {
		return categoryService.selectSecondCategory(topCategoryId);
	}

}
